"""
内容：放置添加商品的page
作者：7
"""
from ECshop.common.base import Base,create_browser_op,base_sql_add
import time
# 创建类
class PageAdminGoods(Base):
    url = 'http://localhost:8080/ecshop/admin'  # 网页
    nav_frame_name = 'menu-frame'   # 左侧导航栏的frame
    main_frame_name = 'main-frame'  # 主要界面的frame
    goods_manage = ('css selector','li[key="02_cat_and_goods"]')  # 商品管理按钮
    goods_list = ('id','sub-menu-01_goods_list')       # 商品列表按钮
    add_good=('css selector','a[href="goods.php?act=add"]')   # 添加商品按钮
    good_name = ('name','goods_name')   # 添加商品的名称
    select_type = ('css selector','select[name="cat_id"]')     # 商品的类别下拉框
    select_add = ('css selector','button[onclick="rapidCatAdd()"]')  # 添加商品的分类
    select_add_input=('name','addedCategoryName')   # 输入新添加的商品分类的名称
    select_add_confirm = ('css selector','button[onclick="addCategory()"]')   # 确认按钮
    goods_price = ('name','shop_price')   # 输入商品的价格
    goods_price_button = ('css selector','input[value="按市场价计算"]')
    add_good_button = ('css selector','input[value=" 确定 "]')
    sql = 'select goods_name from ecs_goods order by goods_id'
    """打开网页"""
    def page_admin_goods_open_web(self):
        self.base_open_web(self.url)
    """进入左侧导航栏的frame"""
    def page_admin_add_goods_in_nav_frame(self):
        self.base_in_frame(self.nav_frame_name)
    """点击商品管理"""
    def page_admin_add_goods_manage(self):
        self.base_click(self.goods_manage)
    """点击商品列表"""
    def page_admin_add_goods_list(self):
        self.base_click(self.goods_list)
    """退出frame"""
    def page_admin_add_goods_out_frame(self):
        self.base_quit_frame()
    """进入主frame"""
    def page_admin_add_goods_in_main_frame(self):
        self.base_in_frame(self.main_frame_name)
    """点击添加商品"""
    def page_admin_add_goods_add_button(self):
        self.base_click(self.add_good)
    """输入新的商品的名称"""
    def page_admin_add_goods_good_name(self,your_content):
        self.base_input_content(self.good_name,your_content)
    """下拉框选择商品分类"""
    def page_admin_add_goods_select_type(self,yours):
        self.base_select(self.select_type,yours)
    """添加商品的分类"""
    def page_admin_add_goods_select_add(self):
        self.base_click(self.select_add)
    """输入商品的分类"""
    def page_admin_add_goods_input_select(self,your_content):
        self.base_input_content(self.select_add_input,your_content)
    """点击确认按钮"""
    def page_admin_add_goods_confirm_button(self):
        self.base_click(self.select_add_confirm)
    """退格"""
    def page_admin_add_goods_space(self):
        self.base_backspace(self.goods_price)

    """滚动条"""

    def page_admin_add_goods_roll_price(self):
        self.base_roll(self.goods_price)
    """输入商品价格"""
    def page_admin_add_goods_price(self,your_content):
        self.base_input_content(self.goods_price,your_content)

    """点击按市场价计算"""
    def page_admin_add_goods_price_button(self):
        self.base_click(self.goods_price_button)
    """滚动条"""
    def page_admin_add_goods_roll(self):
        self.base_roll(self.add_good_button)
    """点击确认按钮"""
    def page_admin_add_goods_button(self):
        self.base_click(self.add_good_button)
    """校验数据库"""
    def page_admin_add_goods_sql(self,key):
        return base_sql_add(self.sql,key)
    """关闭"""
    def page_admin_add_goods_quit(self):
        self.base_quit()
if __name__ == '__main__':
    p1 = PageAdminGoods(create_browser_op(r'C:\Users\23160\AppData\Local\Google\Chrome\User Data'))
    p1.page_admin_goods_open_web()
    p1.page_admin_add_goods_in_nav_frame()
    p1.page_admin_add_goods_manage()
    p1.page_admin_add_goods_list()
    p1.base_quit_frame()
    p1.page_admin_add_goods_in_main_frame()
    p1.page_admin_add_goods_add_button()
    # p1.page_admin_add_goods_in_main_frame()
    time.sleep(5)
    p1.page_admin_add_goods_good_name('直升机')
    time.sleep(5)
    p1.page_admin_add_goods_select_type('配件')
    # time.sleep(5)
    # p1.page_admin_add_goods_select_type()
    # time.sleep(5)
    # p1.page_admin_add_goods_select()
    time.sleep(5)
    p1.page_admin_add_goods_price('34')
    time.sleep(10)
    p1.page_admin_add_goods_price_button()
    time.sleep(5)
    p1.page_admin_add_goods_button()
    time.sleep(5)
    p1.page_admin_add_goods_quit()